import streamlit as st
from llm import initialize_llm, get_chain
from prompt import decision_making_agent_prompt, prompt  # ***修改处***引入 prompt

def sidebar():
    # API Key configuration
    with st.sidebar:
        st.header("API配置")
        api_key = st.text_input("API密钥", type="password", help="输入您的API密钥以使用豆包大模型")

        # 保存API密钥按钮
        if st.button("保存API密钥"):
            if api_key:
                # Update the LLMs with the new API key
                try:
                    # Initialize new LLM instances with the provided API key
                    llm = initialize_llm(api_key)
                    
                    # Store in session state
                    st.session_state.llm = llm
                    
                    # Update the chain with the new LLM
                    st.session_state.chain = get_chain(prompt, llm)
                    st.session_state.api_key_configured = True
                    st.success("API密钥配置成功！")
                except Exception as e:
                    st.error(f"配置API密钥时出错: {str(e)}")
            else:
                st.error("请输入有效的API密钥")
            